<?php
/**
 * @return
 * @author 朱乐斌
 * @date
 */

namespace app\api\controller;

use app\api\model\UserGxModel;
use think\Request;

class Type extends BaseController
{

    // 判断用户类型
    public function type(Request $request)
    {
        $userType = UserGxModel::where('phone',$request->phone)->value('type');
        if ($userType === 0) return errMsg('请选择角色');
        return json([
           'msg' => '成功',
           'code' => 1,
           'data' => 'type:'.$userType
        ]);
    }

    // 登录选择角色
    public function typeAdd(Request $request)
    {
        // 接收数据
        $data = $this->request->post('type/d');
        // 判断用户的角色是否为0
        $userType = UserGxModel::where('phone',$request->phone)->find();
        if ($userType['type'] != 0) return errMsg('欢迎登录');
        // 实例化模型将type存入当前账号
        if (empty($data)) return  errMsg('请选择角色');
        $userDate = [
          'type' =>  $data
        ];
        // 更改数据
        $userType = $userType->where('phone',$request->phone)->save($userDate);
        if ($userType) $this->success('登录成功');
    }

}